package com.problem.leetcode;

/**
 * 给定一个已排序的链表的头 head ， 删除所有重复的元素，使每个元素只出现一次 。返回 已排序的链表 。
 */
public class Problem83 {

    public static void main(String[] args) {
//        deleteDuplicates()
    }

    public ListNode deleteDuplicates(ListNode head) {

        ListNode tmpHead = head.next;
        ListNode nextNode = tmpHead.next;

        while (nextNode.next != null) {
            if (tmpHead.val == nextNode.val) {
                ListNode tmp = nextNode;
                nextNode = nextNode.next;
                tmpHead.next = nextNode;
                tmp.next = null;

            }
            tmpHead = tmpHead.next;
        }


        return head;

    }


    public class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }


}
